//创建Tabbar_isFold小仓库
import { defineStore } from 'pinia'
import { reqC1, reqC2, reqC3 } from '../../../api/product/attr/index.ts'
import type { CategoryResponseData } from '../../../api/product/attr/type'
import type { CategoryState } from '../types/types.ts'

const useCategoryStore = defineStore('category', {
  state: (): CategoryState => {
    return {
      C1Id: 0,
      C2Id: 0,
      C3Id: 0,
      C1Arr: [],
      C2Arr: [],
      C3Arr: [],
    }
  },
  actions: {
    /*    async getC1() {
            //发请求获取一级分类的数据
            const result: CategoryResponseData = await reqC1()
            if (result.code == 200) {
              this.c1Arr = result.data
            }
          }, */
    async getC1() {
      try {
        const res: CategoryResponseData = await reqC1()
        this.C1Arr = res.data
      } catch (error) {
        return Promise.reject('C1错误')
      }
    },
    async getC2() {
      try {
        const res: CategoryResponseData = await reqC2(this.C1Id)
        this.C2Arr = res.data
      } catch (error) {
        return Promise.reject('C2错误')
      }
    },
    async getC3() {
      try {
        const res: CategoryResponseData = await reqC3(this.C2Id)
        this.C3Arr = res.data
      } catch (error) {
        return Promise.reject('C3错误')
      }
    },
  },
  getters: {},
})
export default useCategoryStore
